<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>模拟数字游戏</title>
</head>
<body>
<script>
    //如果用全局变量统计将会不断在gameStart时累积下去
    //注释的两个变量，代表本程序是按每一次点击计算，而不是不断点击累积与先前的总和的
    //var win = 0;
    //var winPercent = 0;
    function gameStart()
    {
        var win = 0;
        var winPercent = 0;
        var lukyNum = document.getElementById("lukyNum").value;
        var game = document.getElementById("game").value;
        var randomNum = new Array(3);
        for(var i=0;i!=game;i++)
        {
            for(var j=0;j!=randomNum.length;j++)
            {
                randomNum[j] = Math.floor(Math.random()*10);
                if(lukyNum == randomNum[j])
                    win++;
            }
        }
        document.getElementById("win").value = win;
        document.getElementById("winPercent").value = (win / game * 100) + "%";
    }
</script>
<html>
设定幸运数字：<input type="text" value = "0" id = "lukyNum"><br />
设定游戏次数: <input type="text" value = "0" id = "game"><br />
<input type="button" value="运行" onclick = "gameStart()"><br />
<input type="text" value="0"  id = "win"></p>
<input type="text" value="0%" id = "winPercent"></p>
</html>
</body>
</html>